﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;


namespace NNLInterface
{
    class ReportShow
    {
        public static bool ShowReport(DevExpress.XtraReports.UI.XtraReport report, bool preview,DataTable dte)
        {
            try
            {
                if (preview)
                {
                    //DataTable dte;
                    //dte = common._its_accessdb.GetRecord("select top 2  vbm.MaterialNo  ,vbm.MaterialName FROM BasMaterial vbm  ").ADODataRst;
                    ////dte = new DataTable("mid");
                    //DataColumn x0 = new DataColumn("MaterialNo", typeof(string));
                    //DataColumn x1 = new DataColumn("MaterialNo1", typeof(string));


                    //dte.Columns.Add(x0);
                    //dte.Columns.Add(x1);


                    //dte.Rows.Add(new object[] { "12345675d fffff","test"});
                    //dte.Rows.Add(new object[] { "12345!A1","dsds" });
                    //dte.Rows.Add(new object[] { "1234567" ,""});
                    //dte.Rows.Add(new object[] { "1234567","" });
                    report.RequestParameters = false;
                    //report.Parameters[0].Value = "这是参数!!";
                    //report.DataMember = null;
                    //report.DataSource=null;

                    report.DataSource = dte;
                   
                    report.ShowPreviewDialog();
                }
                else
                {
                    //PrintDocument prtdoc = new PrintDocument();
                    //string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名
                    report.RequestParameters = false;

                    //report.Parameters[0].Value = "这是参数!!";
                    //report.DataMember = null;
                    //report.DataSource=null;

                    report.DataSource = dte;
                    report.Print();
                    //report.PrintDialog();
                    //report.Print(PrinterName);

                    //foreach (String strPrinter in PrinterSettings.InstalledPrinters)
                    //在列表框中列出所有的打印机,
                    //{
                    //    printerList.Items.Add(strPrinter);
                    //    if (strPrinter == strDefaultPrinter)//把默认打印机设为缺省值
                    //    {
                    //        printerList.SelectedIndex = printerList.Items.IndexOf(strPrinter);
                    //    }
                    //}
                    //

                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message , common.sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            finally
            {
                
            }
            return true;
        }
    }
}
